/*
 * Random.cpp
 *
 *  Created on: 14/09/2013
 *      Author: gonzalo
 */

#include "Random.h"

int Random::scale = 1;

Random::Random() {
}

int Random::randomInt(int desde, int hasta) {
	struct timeval time;
	gettimeofday(&time, NULL);
	srand((int) time.tv_usec);
    int rango = hasta - desde + 1;
    return desde + int(rango * (double) rand() / RAND_MAX);
}

void Random::setScale(int s) {
	/* From 1 to 100 */
	if (scale > 1 && scale <= 100) {
		scale = s;
	}
}

void Random::msleep(int durationMS, int startMs){
	int usToSleep = floor(Random::randomInt(startMs*1000, (durationMS+startMs)*1000) / scale);
	usleep(usToSleep);
}

bool Random::coin() {
	int cara = Random::randomInt(0,1);
	return (bool) cara;
}

Random::~Random() {
}

